package net.csdn.business.mirror.enums;

import lombok.AllArgsConstructor;
import net.csdn.business.mirror.entity.bean.ScheduleTask;
import net.csdn.business.mirror.scheduled.handler.ReleaseTask;

import java.util.function.Function;


/**
 * 动态任务2
 * 定时任务类型枚举
 */
@AllArgsConstructor
public enum TaskType {

    /**
     * 发布任务
     */
    RELEASE(scheduleTask -> new ReleaseTask(scheduleTask)) {
        @Override
        public String getKey(ScheduleTask scheduleTask) {
            return "release-" + scheduleTask.getId();
        }
    },
    ;

    private final Function<ScheduleTask, Runnable> factory;

    /**
     * 创建任务
     */
    public Runnable create(ScheduleTask scheduleTask) {
        return factory.apply(scheduleTask);
    }

    /**
     * 获取 key
     */
    public abstract String getKey(ScheduleTask scheduleTask);

}
